export const useProbability = (selectdForgeItem: Ref<API.Forge.ForgeItem>) => {
  const probability = ref<number>();

  const minMax = computed(() => {
    return {
      min: Number(selectdForgeItem.value?.min_probability || 0),
      max: Number(selectdForgeItem.value?.max_probability || 0),
    };
  });

  const ratios = computed(() => {
    return [
      {
        label: "Min",
        value: minMax.value.min,
      },
      {
        label: "10%",
        value: 0.1,
      },
      {
        label: "25%",
        value: 0.25,
      },
      {
        label: "50%",
        value: 0.5,
      },
      {
        label: "70%",
        value: 0.7,
      },
      {
        label: "Max",
        value: minMax.value.max,
      },
    ];
  });

  const amount = computed(() => {
    if (probability.value !== void 0) {
      return (
        (Number(selectdForgeItem.value?.product?.amount || 0) *
          probability.value) /
        Number(selectdForgeItem.value?.discount_probability || 1)
      ).toFixed(2);
    }
    return selectdForgeItem.value?.default_spin_amount || 0;
  });

  watchEffect(() => {
    if (selectdForgeItem.value?.default_spin_probability) {
      probability.value = Number(
        selectdForgeItem.value?.default_spin_probability
      );
    }
  });

  return {
    minMax,
    amount,
    probability,
    ratios,
  };
};
